<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>

    <script src="jquery.min.js"></script>

    <!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
    <link rel="stylesheet" href="./bootstrap-3.4.1-dist/css/bootstrap.min.css" integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">

    <!-- 可选的 Bootstrap 主题文件（一般不用引入） -->
    <link rel="stylesheet" href="./bootstrap-3.4.1-dist/css/bootstrap-theme.min.css" integrity="sha384-6pzBo3FDv/PJ8r2KRkGHifhEocL+1X2rVCTTkUfGk7/0pbek5mMa1upzvWbrUbOZ" crossorigin="anonymous">

    <!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
    <script src="./bootstrap-3.4.1-dist/js/bootstrap.min.js" integrity="sha384-aJ21OjlMXNL5UyIl/XNwTMqvzeRMZH2w8c5cRVpzpU8Y5bApTppSuUkhZXN0VxHd" crossorigin="anonymous"></script>

    <script src="https://wwcdn.weixin.qq.com/node/open/js/wecom-jssdk-1.3.1.js"></script>

</head>
<body>


<h1>这是Debot小分队</h1>
code:<h2 id="access_token"></h2>
response data:<h2 id="response_data"></h2>
cooike userId:<h2 id="cookie_userid"></h2>
cooike userinfo:<h2 id="cookie_userinfo"></h2>
error:<h2 id="error"></h2>

</body>

<script type="text/javascript">
function getQueryString(name) {
  var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
  var r = window.location.search.substr(1).match(reg);
  if (r != null) return unescape(r[2]);
  return null;
}

function generateUUID() {
  return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
    var r = Math.random() * 16 | 0,
        v = c === 'x' ? r : (r & 0x3 | 0x8);
    return v.toString(16);
  });
}

function getCookie(name) {
    var value = "; " + document.cookie;
    var parts = value.split("; " + name + "=");
    if (parts.length == 2) return parts.pop().split(";").shift();
}


function setCookie(name, value, second) {
  var expires = "";
  if (second) {
    var date = new Date();
    date.setTime(date.getTime() + (second * 1000));
    expires = "; expires=" + date.toUTCString();
  }
  document.cookie = name + "=" + (value || "") + expires + "; path=/";
}

// 使用示例：设置一个名为 "username" 的cookie，值为 "张三"，有效期为30天
//setCookie("username", "张三", 30);


var nonceStr = generateUUID().replaceAll("-","")
console.log(nonceStr);

var timestamp = Date.now();
console.log(timestamp);



</script>



<script type="text/javascript">

    var HOST = "/api"

    var corpid = "ww66a46b9d7ff0633c"

    var corpsecret = "TMwbxgndcC_NiBQFR7MMUjMfk-RKLlfVS6CwxG73tF4"

    var access_token = "U7GiwWkkBhfwCTR6Dlp7bKxLZ0XsDhEjPoOXAxhVwGB4MfXKeAasWxoWUrhfyT-GVVs84_VT1jOfrotdbqpujVWSH1pBQ_2GvO_2Y5NMPV2GMqq2Gwy6WUiEMhDy6GH0kiQSI7ePDAzAroTKjGl6IzQlVRwjw-80-cf-lR4BaBnuV0rdh7wXeTvrHZZPel9l1f_D1x9RDetIt6S0td0V7A"

    var code = "";

    $(document).ready(function(){



        code = getQueryString("code");

        var cookie_userid = getCookie("cookie_userid");
        var cookie_userinfo = getCookie("cookie_userinfo");
        $("#cookie_userid").html(cookie_userid)
        $("#cookie_userinfo").html(cookie_userinfo)

        $("#access_token").html(code)


        var getuserinfo = function(){
            $.ajax({
                //请求方式
                type : "get",
                //请求地址
                url : "/app/api/webchat/getuserinfo?code="+code,
                data : {

                },
                dataType:"JSON",
                //请求成功
                success : function(result) {
                    //设置cookie
                    setCookie("cookie_userid", JSON.parse(result.data).userid, 60);
                    var cookie_userid = getCookie("cookie_userid");
                    $("#cookie_userid").html(cookie_userid)

                    setCookie("cookie_userinfo", result.data, 60);
                    var cookie_userinfo = getCookie("cookie_userinfo");
                    $("#cookie_userinfo").html(cookie_userinfo)

                    $("#response_data").html(result.data)


                },
                //请求失败，包含具体的错误信息
                error : function(e){
                        debugger
                       $("#error").html(e)
                }
            });
        }

        if(cookie_userid==null||cookie_userid==""||cookie_userinfo==null||cookie_userinfo==""){
            getuserinfo();
        }


    });


</script>





</html>


